/* eslint-disable */
import { createStore } from "vuex";
import { bannerApi, classifyApi } from "@/utils/api";

interface ClassifyItemType {
  imgUrl: string;
  productId: string;
  title: string;
  type: string;
}

interface IndexStateType {
  bannerList: string[];
  classifyList: ClassifyItemType[];
}

const indexModule = {
  namespaced: true,
  state: {
    bannerList: [],
    classifyList: [],
  },
  mutations: {
    getBanner(state: IndexStateType, payload: any) {
      state.bannerList = payload.list;
    },
    getClassify(state: IndexStateType, payload: any) {
      state.classifyList = payload.result;
    },
  },
  actions: {
    async getBannerAsync({ commit }: any) {
      const res = await bannerApi({ a: 3 });
      commit("getBanner", { list: res.result.list });
    },
    async getClassifyAsync({ commit }: any, type: string) {
      const res = await classifyApi({ type });
      commit("getClassify", res);
    },
  },
};

export default createStore({
  modules: {
    index: indexModule,
  },
});
